<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function aaa(nums) {
      let [arr, ...all] = nums;
      for (const item of all) {
        arr = arr.filter((c) => item.includes(c));
      }
      return arr.sort((a, b) => a - b);
    };
    console.log(aaa([[3, 1, 2, 4, 5], [1, 2, 3, 4], [3, 4, 5, 6]]));
  </script>
</body>

</html>